﻿using System;

namespace YArchitech.HCLoad.XmlData
{
	public class RoomLoadResult : Result
	{
		public RoomLoadResult()
		{
			this.m_loadItem = null;
			this.m_type = HcObjectType.LO_Unknown;
		}

		public RoomLoadResult(RoomLoad loadItem)
		{
			this.Attach(loadItem);
		}

		public bool Attach(RoomLoad loadItem)
		{
			this.m_loadItem = loadItem;
			this.m_type = loadItem.LoadType;
			this.m_arrZLFHAll = this.m_loadItem.ZsLfhAll;
			this.m_arrZLFhQr = this.m_loadItem.ZsLfhQr;
			this.m_arrZLFhXr = this.m_loadItem.ZsLfhXr;
			this.m_arrZSFh = this.m_loadItem.ZsSfh;
			this.m_dDJRFHXr = this.m_loadItem.DjRfhXr;
			this.m_dDJRFHQr = this.m_loadItem.DjRfhQr;
			this.m_dDJSFH = this.m_loadItem.DjSfh;
			this.m_nMaxTime = Result.GetMaxValueIndex(this.m_arrZLFHAll);
			return true;
		}

		public void AppendToHeatLoad(ref ConsumedHeatingResult heatingLoad)
		{
			switch (this.m_type)
			{
			case HcObjectType.LO_Roof:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_SkyLight:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_OutWall:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_OutWindow:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				heatingLoad.GapFilterAirLoad += this.m_loadItem.Q2;
				break;
			case HcObjectType.LO_InWall:
			case HcObjectType.LO_InWindow:
			case HcObjectType.LO_Stringboard:
			case HcObjectType.LO_InDoor:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				if (this.m_loadItem.IsHjCr)
				{
					heatingLoad.InterRoomHeatLoad += this.m_loadItem.HjFh;
					return;
				}
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_OutDoor:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				heatingLoad.GapFilterAirLoad += this.m_loadItem.Q2;
				heatingLoad.DoorOpenHeatLoad += this.m_loadItem.Q3;
				return;
			case HcObjectType.LO_Ground:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_AerialBoard:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_FlyWindow:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				heatingLoad.GapFilterAirLoad += this.m_loadItem.Q2;
				return;
			case HcObjectType.LO_ArcWall:
				heatingLoad.BaseHeatLoad += this.m_loadItem.Qj;
				heatingLoad.AdditionHeatLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_FreshAir:
				break;
			case HcObjectType.LO_Body:
				heatingLoad.OtherHeatLoad += this.m_loadItem.DjRfhXr + this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_Lighting:
				heatingLoad.OtherHeatLoad += this.m_loadItem.DjRfhXr + this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_Equipment:
				heatingLoad.OtherHeatLoad += this.m_loadItem.DjRfhXr + this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_Food:
				heatingLoad.OtherHeatLoad += this.m_loadItem.DjRfhXr + this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_Chemistry:
				heatingLoad.OtherHeatLoad += this.m_loadItem.DjRfhXr + this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_Water:
				heatingLoad.OtherHeatLoad += this.m_loadItem.DjRfhXr + this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_FlowWater:
				heatingLoad.OtherHeatLoad += this.m_loadItem.DjRfhXr + this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_Filter:
				heatingLoad.AirFilterLoad += this.m_loadItem.DjRfhQr + this.m_loadItem.DjRfhXr;
				return;
			case HcObjectType.LO_Other:
				heatingLoad.OtherHeatLoad += this.m_loadItem.HeatLoad;
				return;
			default:
				return;
			}
		}

		public void AppendToKTLoad(ref AirConditioningHeatingResult ktload)
		{
			switch (this.m_type)
			{
			case HcObjectType.LO_Roof:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_SkyLight:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_OutWall:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_OutWindow:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1 + this.m_loadItem.Q2;
				return;
			case HcObjectType.LO_InWall:
			case HcObjectType.LO_InWindow:
			case HcObjectType.LO_Stringboard:
			case HcObjectType.LO_InDoor:
				if (this.m_loadItem.IsHjCr)
				{
					ktload.HeatingSensibleLoad += this.m_loadItem.HjFh;
					return;
				}
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_OutDoor:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1 + this.m_loadItem.Q2 + this.m_loadItem.Q3;
				return;
			case HcObjectType.LO_Ground:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_AerialBoard:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_FlyWindow:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1 + this.m_loadItem.Q2;
				return;
			case HcObjectType.LO_ArcWall:
				ktload.HeatingSensibleLoad += this.m_loadItem.Q1;
				return;
			case HcObjectType.LO_FreshAir:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingSensibleLoad -= this.m_loadItem.HeatTakeonXrLoad;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				ktload.HeatingLatentLoad -= this.m_loadItem.HeatTakeonQrLoad;
				ktload.HeatingHumidityLoad += this.m_loadItem.DjSfh;
				ktload.HeatingHumidityLoad -= this.m_loadItem.HeatTakeonsLoad;
				return;
			case HcObjectType.LO_Body:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				ktload.HeatingHumidityLoad += this.m_loadItem.DjSfh;
				return;
			case HcObjectType.LO_Lighting:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_Equipment:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				return;
			case HcObjectType.LO_Food:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				ktload.HeatingHumidityLoad += this.m_loadItem.DjSfh;
				return;
			case HcObjectType.LO_Chemistry:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				ktload.HeatingHumidityLoad += this.m_loadItem.DjSfh;
				return;
			case HcObjectType.LO_Water:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				ktload.HeatingHumidityLoad += this.m_loadItem.DjSfh;
				return;
			case HcObjectType.LO_FlowWater:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				ktload.HeatingHumidityLoad += this.m_loadItem.DjSfh;
				return;
			case HcObjectType.LO_Filter:
				ktload.HeatingSensibleLoad += this.m_loadItem.DjRfhXr;
				ktload.HeatingLatentLoad += this.m_loadItem.DjRfhQr;
				ktload.HeatingHumidityLoad += this.m_loadItem.DjSfh;
				return;
			case HcObjectType.LO_Other:
				ktload.HeatingSensibleLoad += this.m_loadItem.HeatLoad;
				ktload.HeatingHumidityLoad += this.m_loadItem.DjSfh;
				return;
			default:
				return;
			}
		}

		public void AppendToXFDealLoad(ref Result XFDealLoad)
		{
			HcObjectType type = this.m_type;
			if (type == HcObjectType.LO_FreshAir)
			{
				double[] coolingSensibleLoad = XFDealLoad.CoolingSensibleLoad;
				Result.Append(ref coolingSensibleLoad, this.m_loadItem.TakeonXrLoad);
				double[] coolingLatentLoad = XFDealLoad.CoolingLatentLoad;
				Result.Append(ref coolingLatentLoad, this.m_loadItem.TakeonQrLoad);
				double[] coolingHumidityLoad = XFDealLoad.CoolingHumidityLoad;
				Result.Append(ref coolingHumidityLoad, this.m_loadItem.TakeonSLoad);
				XFDealLoad.HeatingSensibleLoad += this.m_loadItem.HeatTakeonXrLoad;
				XFDealLoad.HeatingLatentLoad += this.m_loadItem.HeatTakeonQrLoad;
				XFDealLoad.HeatingHumidityLoad += this.m_loadItem.HeatTakeonsLoad;
			}
		}

		private RoomLoad m_loadItem;

		private HcObjectType m_type;
	}
}
